/**
 *  
 * 
 */

class Cattle {
  constructor (age) {
    this.age = age
    this.alive = true
  }

  addAge(){
    this.age+=1
    if (this.age > 15) {
      this.alive = false
    }
  }
  getAge(){
    return this.age
  }

  getAlive () {
    return this.alive
  }
}

class Form {
  constructor() {
    this.cattleList = []
    this.init()
  }
  init(){
    this.cattleList.push(new Cattle(5))
  }
  addCattle(arr){
    // console.log(arr)
    this.cattleList = this.cattleList.concat(arr)
  }
  getCattleList () {
    return this.cattleList
  }
}

class Main {
  constructor(){
    this.form = new Form()
    this.init()
  }
  init () {
    for (let i=0;i < 20;i++){
      const cattlelists = this.form.getCattleList()
      // console.log(cattlelists.length)
      let newArr = []
      let deaded = 0
      cattlelists.forEach(cattle=>{
        cattle.addAge()
        const age = cattle.getAge()
        if (age >= 5 && age <= 15) {
          newArr.push(new Cattle(0))
        }
        if (!cattle.getAlive()) {
          deaded++
        }
      })
      // console.log(newArr)
      this.form.addCattle(newArr)
      console.log(`第${i+1}年，生育了${newArr.length}头牛，死亡了${deaded}头牛`)
    }
    console.log(this.form.getCattleList().length)
  }
}

new Main()

